using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;

using SR = System.Reflection;
using SRE = System.Reflection.Emit;

using Multiplicity.Runtime.Serialization.Binary;

namespace Multiplicity.Reflection {

    enum HeapType : uint {
        Strings = 0x1,
        Guid = 0x2,
        Blob = 0x4
    }

    [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
    sealed class HeapIndexAttribute : Attribute {

        readonly HeapType heap;

        public HeapIndexAttribute(HeapType heap) {
            this.heap = heap;
        }

        public HeapType Heap {
            get { return heap; }
        }
    }

    [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
    sealed class CodedTokenAttribute : Attribute {

        readonly CodedTokenFamilyType familyId;

        public CodedTokenAttribute(CodedTokenFamilyType family) {
            this.familyId = family;
        }

        public CodedTokenFamilyType Family {
            get { return familyId; }
        }
    }

    [AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
    sealed class TableIndexAttribute : Attribute {

        readonly MetadataTableType table;

        public TableIndexAttribute(MetadataTableType table) {
            this.table = table;
        }

        public MetadataTableType Table {
            get { return table; }
        }
    }

    sealed class MetadataStream : MetadataParser {

        public const string Name = "#~";

        readonly Module module;

        internal MetadataStream(Module module, StorageHeapHeader heapHead, long storageOffset)
            : base(new BufferSegment(module.Image, heapHead.Offset + (uint)storageOffset, heapHead.Size)) {

            this.module = module;
            this.Header = new MetadataStreamHeader(this);
        }

    }


}
